import Vue from 'vue'
import Router from 'vue-router'
const _import = require('./_import_' + process.env.NODE_ENV)
// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
**/
export const constantRouterMap = [
  { path: '/login', component: _import('login/index'), hidden: true },
  { path: '/register', component: _import('register/index'), hidden: true },
  { path: '/company', component: _import('company/index'), hidden: true },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    name: '首页概览',
    meta: { title: '首页概览', icon: 'example', role: ['ROLE_ADMIN', 'ROLE_USER'] },
    children: [{
      path: '/dashboard',
      component: _import('dashboard/index')
    }]
  },
  {
    path: '/timedata',
    component: Layout,
    redirect: '/timedata/index',
    name: '实时数据',
    meta: { title: '实时数据', icon: 'example', role: ['ROLE_ADMIN', 'ROLE_USER'] },
    children: [{
      path: '/timedata/index',
      component: _import('timedata/index'),
      meta: { title: '实时数据', icon: 'example', role: ['ROLE_ADMIN', 'ROLE_USER'] }
    }]
  },
  {
    path: '/timedata/history',
    component: Layout,
    redirect: '/timedata/history/index',
    children: [{
      path: '/timedata/history/index',
      component: _import('timedata/history'),
      meta: { title: '实时数据', icon: 'example', role: ['ROLE_ADMIN', 'ROLE_USER'] }
    }],
    hidden: true
  },
  {
    path: '/watch',
    component: Layout,
    redirect: '/watch/index',
    name: '供气监测',
    meta: { title: '供气监测', icon: 'example', role: ['ROLE_ADMIN', 'ROLE_USER'] },
    children: [{
      path: 'index',
      component: _import('watch/index'),
      meta: { title: '实时数据', icon: 'example', role: ['ROLE_ADMIN', 'ROLE_USER'] }

    }]
  },
  {
    path: '/anilises',
    component: Layout,
    redirect: '/anilises/temperature',
    name: '供气分析',
    meta: { title: '供气分析', icon: 'example', role: ['ROLE_ADMIN', 'ROLE_USER'] },
    children: [{
      path: '/anilises/temperature',
      component: _import('analyze/temperature'),
      meta: { title: '温度分析', icon: 'example', role: ['ROLE_ADMIN', 'ROLE_USER'] }
    }, {
      path: '/anilises/pressure',
      component: _import('analyze/pressure'),
      meta: { title: '压力分析', icon: 'example', role: ['ROLE_ADMIN', 'ROLE_USER'] }
    }, {
      path: '/anilises/flow',
      component: _import('analyze/flow'),
      meta: { title: '流量分析', icon: 'example', role: ['ROLE_ADMIN', 'ROLE_USER'] }
    }, {
      path: '/anilises/flowDistribution',
      component: _import('analyze/flowDistribution'),
      meta: { title: '流量分布分析', icon: 'example', role: ['ROLE_ADMIN', 'ROLE_USER'] }
    }]
  },
  {
    path: '/alarm',
    component: Layout,
    redirect: '/alarm/index',
    name: '预警监测',
    meta: { title: '历史数据', icon: 'example', role: ['ROLE_ADMIN', 'ROLE_USER'] },
    children: [{
      path: 'index',
      component: _import('alarm/index')
    }]
  },
  {
    path: '/history',
    name: '历史数据',
    redirect: '/history/index',
    component: Layout,
    meta: { title: '历史数据', icon: 'example', role: ['ROLE_ADMIN', 'ROLE_USER'] },
    children: [{
      path: 'index',
      component: _import('device/communicate/history')
    }]
  },
  {
    path: '/yibiao',
    component: Layout,
    redirect: '/yibiao/index',
    name: '仪表管理',
    meta: { title: '历史数据', icon: 'example', role: ['ROLE_ADMIN', 'ROLE_USER'] },
    children: [{
      path: '/yibiao',
      component: _import('device/communicate/history')
    }]
  },
  {
    path: '/device',
    component: Layout,
    redirect: '/device/group',
    name: '设备管理',
    meta: { title: '设备管理', icon: 'example', role: ['ROLE_ADMIN'] },
    children: [
      {
        path: 'group',
        name: '通讯模块管理',
        component: _import('device/communicate/index'),
        meta: { title: '通讯模块管理', icon: 'tree' }
      }
      // , {
      //   path: 'device_info',
      //   name: '设备信息',
      //   hidden: true,
      //   component: _import('device/communicate/deviceDataInfo'),
      //   meta: { title: '通讯模块管理', icon: 'tree' }
      // }
    ]
  },
  {
    path: '/group',
    component: Layout,
    redirect: '/group/index',
    name: '门站管理',
    meta: { title: '门站管理', icon: 'table', role: ['ROLE_ADMIN'] },
    children: [
      {
        path: 'index',
        name: '门站管理',
        component: _import('device/group/index'),
        meta: { title: '门站管理', icon: 'table', role: ['ROLE_ADMIN'] }
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    redirect: '/user/index',
    name: '账户管理',
    meta: { title: '账户管理', icon: 'form', role: ['ROLE_ADMIN'] },
    children: [
      {
        path: 'index',
        name: '子账户管理',
        component: _import('user/subuser/index'),
        meta: { title: '账户管理', icon: 'form', role: ['ROLE_ADMIN'] }
      }
    ]
  },
  {
    path: '/404',
    component: Layout,
    hidden: true,
    children: [{
      path: '/404',
      component: _import('other/index')
    }]
  },
  { path: '*', redirect: '/404', hidden: true }

]

export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

export const asyncRouterMap = [

  // {
  //   path: '/user',
  //   component: Layout,
  //   redirect: '/user',
  //   name: '用户管理',
  //   children: [
  //     {
  //       path: 'index',
  //       name: '子账户管理',
  //       component: _import('user/subuser/index'),
  //       meta: { title: '账户管理', icon: 'form' }
  //     }
  //   ]
  // }
]

